package com.oraclefmw.crusher.core;

import java.util.Properties;
import java.util.concurrent.BlockingQueue;

public class WorkerFactory {

	public static int calWorkerCount(int total, int pageSize) {

		int count = total / pageSize;

		count = (count * pageSize - total > 0) ? count += 1 : count;

		return count;
	}

	public static Worker getInstance(BlockingQueue<Fragment> queue,
			Properties props) {

		String workerType = props.getProperty("worker_type");
		Worker worker = null;

		if (workerType != null) {

			if (workerType.equals("file")) {

				worker = new FileWorker(queue, props);
			} else if (workerType.equals("jms")) {

				worker = new JMSWorker(queue, props);
			} else {

				throw new IllegalArgumentException("unsupported woker type:"
						+ workerType);
			}
		} else {

			throw new IllegalArgumentException("please set 'worker_type'.");
		}

		return worker;
	}
}
